window.onload=function(){
    let txt1=document.querySelector('#txt1');
    let txt2=document.querySelector('#txt2');
    let btn=document.querySelector('.dlbtn');
    // let txt1=document.querySelector('#txt1');
   
    txt1.onchange=function(){
        let str=this.value;
        let reg=/^\w+[-+.]*\w*@([a-z0-9A-Z\u2E80-\u9FFF]-?)+(\.\w{2,6})+/;
        let reg2=/^1[3|4|5|7|8][0-9]{9}$/;
        if(reg.test(str)){
            this.nextElementSibling.innerHTML='邮箱格式正确'
        }else if(reg2.test(str)){
            this.nextElementSibling.innerHTML='手机号格式正确';
        }else{
            this.nextElementSibling.innerHTML='输入不合法';
        }
    }
    // let txt2=document.querySelector('#txt2')
    txt2.onchange=function(){
        let res1=this.value;
        let reg1=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
        if(reg1.test(res1)){
            this.nextElementSibling.innerHTML='密码格式正确'
        }else{
            this.nextElementSibling.innerHTML='密码必须是6~12位'
        }
    }
    btn.onclick=async ()=>{
        let username=txt1.value;
        let password=txt2.value;
        let params={
            username,
            password
        }
        let res1=await axios.get(regisAPI,{params}).then(res=>{
            if(res.data.code==1){
                location.href='./登录界面.html';
            }else{
                alert('已经注册');
            }
        })
    }
}